package com.hjf.booking.module.record.service.impl;

import cn.hutool.core.date.DateUtil;
import com.hjf.booking.constants.BaseResponse;
import com.hjf.booking.module.record.VO.ConsumeRecordReport;
import com.hjf.booking.module.record.mapper.ConsumeRecordMapper;
import com.hjf.booking.module.record.po.ConsumeRecord;
import com.hjf.booking.module.record.service.ConsumeRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author hjf
 * @date 2021-02-22 9:55
 */
@Service
public class ConsumeRecordServiceImpl implements ConsumeRecordService {

    @Autowired
    private ConsumeRecordMapper consumeRecordMapper;

    @Override
    public BaseResponse record(ConsumeRecord consumeRecord) {
        consumeRecordMapper.insertSelective(consumeRecord);
        return BaseResponse.ok();
    }

    @Override
    public BaseResponse dayReport(Date reportDate) {
        Date dayStart = DateUtil.beginOfDay(reportDate);
        Date dayEnd = DateUtil.endOfDay(reportDate);
        Date monthStart = DateUtil.beginOfMonth(reportDate);
        Date monthEnd = DateUtil.endOfMonth(reportDate);
        Date yearStart = DateUtil.beginOfYear(reportDate);
        Date yearEnd = DateUtil.endOfYear(reportDate);

        BigDecimal dayConsume = consumeRecordMapper.dayReport(dayStart,dayEnd);
        BigDecimal monthConsume = consumeRecordMapper.monthReport(monthStart, monthEnd);
        BigDecimal yearConsume = consumeRecordMapper.yearReport(yearStart, yearEnd);
        BigDecimal totalConsume = consumeRecordMapper.totalReport(dayEnd);

        ConsumeRecordReport consumeRecordReport = new ConsumeRecordReport();
        consumeRecordReport.setDayConsume(dayConsume);
        consumeRecordReport.setMonthConsume(monthConsume);
        consumeRecordReport.setYearConsume(yearConsume);
        consumeRecordReport.setTotalConsume(totalConsume);

        return BaseResponse.ok(consumeRecordReport);
    }
}
